home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / interface / OptionsPasvPage.cpp < prev    next >
C/C++ Source or Header  |  2011-11-06  |  6KB  |  179 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 2002-2004 - Tim Kosse <tim.kosse@gmx.de>
  4.  
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. // OptionsPasvPage.cpp: Implementierungsdatei
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "filezilla server.h"
  24. #include "OptionsDlg.h"
  25. #include "OptionsPage.h"
  26. #include "OptionsPasvPage.h"
  27.  
  28. #if defined(_DEBUG) && !defined(MMGR)
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Dialogfeld COptionsPasvPage 
  36.  
  37.  
  38. COptionsPasvPage::COptionsPasvPage(COptionsDlg *pOptionsDlg, CWnd* pParent /*=NULL*/)
  39.     : COptionsPage(pOptionsDlg, COptionsPasvPage::IDD, pParent)
  40. {
  41.     //{{AFX_DATA_INIT(COptionsPasvPage)
  42.     m_URL = _T("");
  43.     m_IP = _T("");
  44.     m_nIPType = -1;
  45.     m_bUseCustomPort = FALSE;
  46.     m_PortMin = _T("");
  47.     m_PortMax = _T("");
  48.     m_Text = CString((LPCTSTR)IDC_OPTIONS_PASV_TEXT);
  49.     //}}AFX_DATA_INIT
  50. }
  51.  
  52.  
  53. void COptionsPasvPage::DoDataExchange(CDataExchange* pDX)
  54. {
  55.     COptionsPage::DoDataExchange(pDX);
  56.     //{{AFX_DATA_MAP(COptionsPasvPage)
  57.     DDX_Control(pDX, IDC_OPTIONS_PASV_PORTMIN, m_cPortMin);
  58.     DDX_Control(pDX, IDC_OPTIONS_PASV_PORTMAX, m_cPortMax);
  59.     DDX_Control(pDX, IDC_OPTIONS_PASV_IP, m_cIP);
  60.     DDX_Control(pDX, IDC_OPTIONS_PASV_URL, m_cURL);
  61.     DDX_Text(pDX, IDC_OPTIONS_PASV_URL, m_URL);
  62.     DDX_Text(pDX, IDC_OPTIONS_PASV_IP, m_IP);
  63.     DDX_Radio(pDX, IDC_OPTIONS_PASV_IPTYPE1, m_nIPType);
  64.     DDX_Check(pDX, IDD_OPTIONS_PASV_USEPORTRANGE, m_bUseCustomPort);
  65.     DDX_Text(pDX, IDC_OPTIONS_PASV_PORTMIN, m_PortMin);
  66.     DDV_MaxChars(pDX, m_PortMin, 5);
  67.     DDX_Text(pDX, IDC_OPTIONS_PASV_PORTMAX, m_PortMax);
  68.     DDV_MaxChars(pDX, m_PortMax, 5);
  69.     DDX_Text(pDX, IDC_OPTIONS_PASV_TEXT, m_Text);
  70.     DDX_Check(pDX, IDC_OPTIONS_PASV_NOLOCAL, m_NoExternalOnLocal);
  71.     //}}AFX_DATA_MAP
  72. }
  73.  
  74.  
  75. BEGIN_MESSAGE_MAP(COptionsPasvPage, COptionsPage)
  76.     //{{AFX_MSG_MAP(COptionsPasvPage)
  77.     ON_BN_CLICKED(IDC_OPTIONS_PASV_IPTYPE2, OnOptionsPasvIptype)
  78.     ON_BN_CLICKED(IDD_OPTIONS_PASV_USEPORTRANGE, OnOptionsPasvUseportrange)
  79.     ON_BN_CLICKED(IDC_OPTIONS_PASV_IPTYPE3, OnOptionsPasvIptype)
  80.     ON_BN_CLICKED(IDC_OPTIONS_PASV_IPTYPE1, OnOptionsPasvIptype)
  81.     //}}AFX_MSG_MAP
  82. END_MESSAGE_MAP()
  83.  
  84. /////////////////////////////////////////////////////////////////////////////
  85. // Behandlungsroutinen fⁿr Nachrichten COptionsPasvPage 
  86.  
  87. void COptionsPasvPage::OnOptionsPasvIptype() 
  88. {
  89.     UpdateData(TRUE);
  90.     m_cIP.EnableWindow(m_nIPType == 1);
  91.     m_cURL.EnableWindow(m_nIPType == 2);    
  92. }
  93.  
  94. void COptionsPasvPage::OnOptionsPasvUseportrange() 
  95. {
  96.     UpdateData(TRUE);
  97.     m_cPortMin.EnableWindow(m_bUseCustomPort);
  98.     m_cPortMax.EnableWindow(m_bUseCustomPort);
  99. }
  100.  
  101. BOOL COptionsPasvPage::OnInitDialog() 
  102. {
  103.     COptionsPage::OnInitDialog();
  104.     
  105.     OnOptionsPasvIptype();
  106.     OnOptionsPasvUseportrange();
  107.  
  108.     return TRUE;  // return TRUE unless you set the focus to a control
  109.                   // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurⁿckgeben
  110. }
  111.  
  112. BOOL COptionsPasvPage::IsDataValid()
  113. {
  114.     if (m_nIPType == 1)
  115.     {
  116.         //Ensure a valid IP address has been entered
  117.         if (m_IP == _T(""))
  118.         {
  119.             m_pOptionsDlg->ShowPage(this);
  120.             GetDlgItem(IDC_OPTIONS_PASV_IP)->SetFocus();
  121.             AfxMessageBox(_T("Please enter a valid IP address or hostname!"));
  122.             return FALSE;
  123.         }
  124.     }
  125.     else if (m_nIPType == 2)
  126.     {
  127.         CString address = m_URL;
  128.         if (address.Left(7) == _T("http://"))
  129.             address = address.Mid(7);
  130.         int pos = address.Find('/');
  131.         if (pos != -1)
  132.             address = address.Left(pos);
  133.  
  134.         if (address == _T("") || address.Find(' ') != -1)
  135.         {
  136.             m_pOptionsDlg->ShowPage(this);
  137.             GetDlgItem(IDC_OPTIONS_PASV_URL)->SetFocus();
  138.             AfxMessageBox(_T("Please enter the complete URL of the IP autodetect server!"));
  139.             return FALSE;
  140.         }
  141.     }
  142.  
  143.     if (m_bUseCustomPort)
  144.     {
  145.         int nPortMin = _ttoi(m_PortMin);
  146.         int nPortMax = _ttoi(m_PortMax);
  147.         if (nPortMin < 1 || nPortMin > 65535 || nPortMax < 1 || nPortMax > 65535 || nPortMin > nPortMax)
  148.         {
  149.             m_pOptionsDlg->ShowPage(this);
  150.             GetDlgItem(IDC_OPTIONS_PASV_PORTMIN)->SetFocus();
  151.             AfxMessageBox(_T("The port values have to be in the range from 1 to 65535. Also, the first value has to be lower than or equal to the second one."));
  152.             return FALSE;
  153.         }
  154.     }
  155.  
  156.     return TRUE;
  157. }
  158.  
  159. void COptionsPasvPage::LoadData()
  160. {
  161.     m_nIPType = (int)m_pOptionsDlg->GetOptionVal(OPTION_CUSTOMPASVIPTYPE);
  162.     m_IP = m_pOptionsDlg->GetOption(OPTION_CUSTOMPASVIP);
  163.     m_URL = m_pOptionsDlg->GetOption(OPTION_CUSTOMPASVIPSERVER);
  164.     m_bUseCustomPort = m_pOptionsDlg->GetOptionVal(OPTION_USECUSTOMPASVPORT) != 0;
  165.     m_PortMin.Format(_T("%d"), static_cast<int>(m_pOptionsDlg->GetOptionVal(OPTION_CUSTOMPASVMINPORT)));
  166.     m_PortMax.Format(_T("%d"), static_cast<int>(m_pOptionsDlg->GetOptionVal(OPTION_CUSTOMPASVMAXPORT)));
  167.     m_NoExternalOnLocal = m_pOptionsDlg->GetOptionVal(OPTION_NOEXTERNALIPONLOCAL) != 0;
  168. }
  169.  
  170. void COptionsPasvPage::SaveData()
  171. {
  172.     m_pOptionsDlg->SetOption(OPTION_CUSTOMPASVIPTYPE, m_nIPType);
  173.     m_pOptionsDlg->SetOption(OPTION_CUSTOMPASVIP, m_IP);
  174.     m_pOptionsDlg->SetOption(OPTION_CUSTOMPASVIPSERVER, m_URL);
  175.     m_pOptionsDlg->SetOption(OPTION_USECUSTOMPASVPORT, m_bUseCustomPort);
  176.     m_pOptionsDlg->SetOption(OPTION_CUSTOMPASVMINPORT, _ttoi(m_PortMin));
  177.     m_pOptionsDlg->SetOption(OPTION_CUSTOMPASVMAXPORT, _ttoi(m_PortMax));
  178.     m_pOptionsDlg->SetOption(OPTION_NOEXTERNALIPONLOCAL, m_NoExternalOnLocal ? 1 : 0);
  179. }